package com.qf.handerException;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.handerException
 * @Description:
 * @Date 2022/10/8 16:07
 *
 * @ControllerAdvice: 控制器通知对象， 当控制器出现异常时通过此对象
 */
//@ControllerAdvice
public class MyHandlerException02 {

    @ExceptionHandler({
            RuntimeException.class
    })
    public ModelAndView handerRuntimeException(RuntimeException e){
        e.printStackTrace();
        ModelAndView mav = new ModelAndView();
        mav.addObject("errorMsg", "运行时异常");
        mav.setViewName("/error.jsp");
        return mav;
    }

    @ExceptionHandler({
            Exception.class
    })
    public ModelAndView handlerOtherException(Exception e){
        e.printStackTrace();
        ModelAndView mav = new ModelAndView();
        mav.addObject("errorMsg","其他异常");
        mav.setViewName("/error.jsp");
        return mav;
    }
}
